var express = require('express');
var router = express.Router();
var DateModule = require('../../databases/date')
const gouwu = DateModule.gouwu

/* GET users listing. */
router.get('/', function (req, res, next) {
  res.send('respond with a resource');
});
// 
router.post('/addcart', async function (req, res, next) {
  try {
    const { shopId, name, img, price, colorx, chima, num, userId } = req.body
    // 这里只做简单示例，实际项目应校验用户登录
    const cartItem = await gouwu.create({
      userId,
      shopId,
      colorx,
      chima,
      num
    })
    res.json({ code: 0, msg: '添加成功', data: cartItem })
  } catch (e) {
    res.json({ code: 1, msg: '添加失败', error: e.message })
  }
})

module.exports = router;